#include "m_roommanage.h"
#include "ui_m_roommanage.h"
#include "m_roominsert.h"

extern QString global_id3;

m_roomManage::m_roomManage(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::m_roomManage)
{
    ui->setupUi(this);
    _querytable();
}

m_roomManage::~m_roomManage()
{
    delete ui;
}

void m_roomManage::_querytable(){
    QString str=QString("select * from room where bui_bid='%1'").arg(global_id3);
    qDebug()<<str;
    model.setQuery(str);
    ui->tableView->setModel(&model);
    ui->tableView->setColumnHidden(4,true);
    model.setHeaderData(0,Qt::Horizontal,"房间号");
    model.setHeaderData(1,Qt::Horizontal,"楼栋号");
    model.setHeaderData(2,Qt::Horizontal,"最大人数");
    model.setHeaderData(3,Qt::Horizontal,"现居住人数");
}
void m_roomManage::on_BinsertBtn_clicked()
{
    m_roomInsert window;
    window.exec();
    _querytable();
}


void m_roomManage::on_BdeleteBtn_clicked()
{
    int row = ui-> tableView ->currentIndex().row();
    QString id=model.data(model.index(row,0)).toString();

    QSqlQuery query;
    QString str=QString("delete from room where rid='%1'").arg(id);
    if(query.exec(str)){
        QMessageBox::information(NULL,"tips","删除成功");
    }
    else {
        QMessageBox::warning(NULL,"Error","删除失败,必须先合理安排楼栋内学生才可删除楼栋");
    }
    _querytable();
}

